﻿namespace Columbus
{
    /// <summary>
    /// Base class for controller action results
    /// </summary>
    public abstract class ActionResult
    {
        private readonly NavigationContext context;

        protected ActionResult(NavigationContext context)
        {
            this.context = context;
        }

        /// <summary>
        /// Executes result.
        /// </summary>
        public void Execute()
        {
            ExecuteInternal();

            if (NeedToSaveRequestInJournal)
                context.NeedToSaveRequestInJournal = true;
        }

        /// <summary>
        /// Executes result.
        /// </summary>
        protected abstract void ExecuteInternal();

        /// <summary>
        /// Gets or sets a value indicating whether navigator needs to save request (that invoked this action) in history journal.
        /// If request is saved in journal it can later be used to navigate back.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if navigator needs to save request in journal; otherwise, <c>false</c>.
        /// </value>
        public bool NeedToSaveRequestInJournal { get; set; }
    }
}